import os

# 获取当前目录下的所有文件
files = os.listdir('.')

# 遍历文件列表
for file_name in files:
    # 检查文件是否为COE文件
    if file_name.endswith('.coe'):
        # 读取COE文件
        with open(file_name, 'r') as coe_file:
            lines = coe_file.readlines()

        # 删除最开始的两行和最后一行
        lines = lines[2:-1]

        # 删除每行中的逗号和分号
        lines = [line.replace(',', '').replace(';', '') for line in lines]

        # 构造新的BIN文件名
        bin_file_name = file_name[:-4] + '.dat'

        # 将修改后的内容写入BIN文件
        with open(bin_file_name, 'w') as bin_file:
            bin_file.writelines(lines)

        print(f'Processed {file_name} and saved as {bin_file_name}')